
import json
from datetime import datetime

from util.Sql_df import SQLServer_df
# sqldf = SQLServer_df()
#
# sql = 'select acl_id,parent_id,acl_name,acl_type,title from acl'
#
# df = sqldf.Query(sql)
# # 模拟角色拥有的权限
# rolacList = [7, 8]
# # 递归函数来构建层级列表
# def build_hierarchy(df, rolacList, parent_id=None, level=1):
#     result = []
#     for index, row in df.iterrows():
#         if row['parent_id'] == parent_id:
#             row_dict = row.to_dict()
#             row_dict['level'] = level
#             # 检查角色是否拥有该权限
#             row_dict['has_permission'] = row['acl_id'] in rolacList
#             children = build_hierarchy(df, rolacList, row['acl_id'], level + 1)
#             if children:
#                 row_dict['children'] = children
#             result.append(row_dict)
#     return result
# # 找到顶层节点，即 parent_id 为 None 的节点
# top_level_nodes = df[df['parent_id'].isnull()]
#
# # 构建层级列表
# hierarchy_list = []
# for index, top_node in top_level_nodes.iterrows():
#     top_node = top_node.fillna(0)  # 将 NaN 替换为 0
#     node_dict = top_node.to_dict()
#     node_dict['level'] = 0 if top_node['parent_id'] == 0 else 1  # 根据顶级节点判断 level
#     # 检查角色是否拥有该权限
#     node_dict['has_permission'] = top_node['acl_id'] in rolacList
#     node_dict['level'] = 1
#     children = build_hierarchy(df, rolacList, top_node['acl_id'], 2)
#     if children:
#         node_dict['children'] = children
#     hierarchy_list.append(node_dict)
#
# # 在最外层再套一个最顶层的节点，叫做 "全部数据"
# all_data = {
#     "acl_id": 0,  # 或者是其他适当的空值，表示这是一个虚拟节点
#     "parent_id": 0,
#     "acl_name": '',
#     "acl_type": '',  # 或者是其他适当的空值，表示这是一个虚拟节点
#     "title": '全部数据',  # 或者是其他适当的空值，表示这是一个虚拟节点
#     "level": 0,  # 设置 level 为 0
#     "has_permission": False,  # 或者根据实际情况设定
#     "children": hierarchy_list
# }
#
# # 序列化为 JSON，并设置ensure_ascii=False保留中文字符
# json_data = json.dumps(all_data, indent=4, ensure_ascii=False)
#
# # 打印 JSON
# print(json_data)

# import pandas as pd
#
# df=pd.DataFrame({'A': [1, 2, 3], 'B': [4, 5, 6]})
# print(df['A'].sum())

print(datetime.now().strftime('%Y-%m-%d %H:%M:%S'))